<?php

$ip = get_client_ip();

$ip_header = explode('.', $ip)[0];

const LCOAL_IP_HEADERS = ['127', '192', '172', '10', '20'];

$is_localhost = in_array($ip_header, LCOAL_IP_HEADERS, false);

if ($is_localhost) {
  define('DB_HOST', 'localhost');
  define('DB_PORT', '3306');
  define('DB_USER', 'cdapp');
  define('DB_PASSWD', 'gzzxjjwt1');
  define('DB_NAME', 'cdapp');
} else {
  // define('DB_HOST', 'cdm823323580.my3w.com');
  // define('DB_PORT', '3306');
  // define('DB_USER', 'cdm823323580');
  // define('DB_PASSWD', 'Inctu2012036');
  // define('DB_NAME', 'cdm823323580_db');
  define('DB_HOST', '172.18.0.1');
  define('DB_PORT', '3306');
  define('DB_USER', 'cdapp');
  define('DB_PASSWD', 'gzzxjjwt1');
  define('DB_NAME', 'cdapp');
}

function get_client_ip() {
  if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) {
    $ip = getenv("HTTP_CLIENT_IP");
  } elseif (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) {
    $ip = getenv("HTTP_X_FORWARDED_FOR");
  } elseif (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) {
    $ip = getenv("REMOTE_ADDR");
  } elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) {
    $ip = $_SERVER['REMOTE_ADDR'];
  } else {
    $ip = "unknown";
  }
  return $ip;
}